@echo off
echo 开始修复所有模块依赖问题...

REM 检查并创建目标目录
if not exist ".\scms-admin\src\main\java\com\scms\secondclass\domain" (
    mkdir ".\scms-admin\src\main\java\com\scms\secondclass\domain"
    echo 创建目录: .\scms-admin\src\main\java\com\scms\secondclass\domain
)

if not exist ".\scms-admin\src\main\java\com\scms\secondclass\mapper" (
    mkdir ".\scms-admin\src\main\java\com\scms\secondclass\mapper"
    echo 创建目录: .\scms-admin\src\main\java\com\scms\secondclass\mapper
)

if not exist ".\scms-admin\src\main\resources\mapper\secondclass" (
    mkdir ".\scms-admin\src\main\resources\mapper\secondclass"
    echo 创建目录: .\scms-admin\src\main\resources\mapper\secondclass
)

if not exist ".\scms-secondclass\src\main\resources\mapper\secondclass" (
    mkdir ".\scms-secondclass\src\main\resources\mapper\secondclass"
    echo 创建目录: .\scms-secondclass\src\main\resources\mapper\secondclass
)

REM 1. 修复ActivityMapper问题
echo 修复ActivityMapper问题...
if exist ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\ActivityMapper.java" (
    copy ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\ActivityMapper.java" ".\scms-admin\src\main\java\com\scms\secondclass\mapper\ActivityMapper.java" /Y
    echo 复制文件: ActivityMapper.java
) else (
    echo 错误: 找不到源文件 ActivityMapper.java
    exit /b 1
)

REM 2. 修复CreditRecordMapper问题
echo 修复CreditRecordMapper问题...
if exist ".\scms-admin\src\main\resources\mapper\secondclass\CreditRecordMapper.xml" (
    copy ".\scms-admin\src\main\resources\mapper\secondclass\CreditRecordMapper.xml" ".\scms-secondclass\src\main\resources\mapper\secondclass\CreditRecordMapper.xml" /Y
    echo 复制文件: CreditRecordMapper.xml
) else (
    echo 错误: 找不到源文件 CreditRecordMapper.xml
    exit /b 1
)

REM 3. 修复Teacher相关问题
echo 修复Teacher相关问题...

REM 复制Teacher.java
if exist ".\scms-secondclass\src\main\java\com\scms\secondclass\domain\Teacher.java" (
    copy ".\scms-secondclass\src\main\java\com\scms\secondclass\domain\Teacher.java" ".\scms-admin\src\main\java\com\scms\secondclass\domain\Teacher.java" /Y
    echo 复制文件: Teacher.java
) else (
    echo 错误: 找不到源文件 Teacher.java
    exit /b 1
)

REM 复制TeacherRole.java
if exist ".\scms-secondclass\src\main\java\com\scms\secondclass\domain\TeacherRole.java" (
    copy ".\scms-secondclass\src\main\java\com\scms\secondclass\domain\TeacherRole.java" ".\scms-admin\src\main\java\com\scms\secondclass\domain\TeacherRole.java" /Y
    echo 复制文件: TeacherRole.java
) else (
    echo 错误: 找不到源文件 TeacherRole.java
    exit /b 1
)

REM 复制TeacherMapper.java
if exist ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\TeacherMapper.java" (
    copy ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\TeacherMapper.java" ".\scms-admin\src\main\java\com\scms\secondclass\mapper\TeacherMapper.java" /Y
    echo 复制文件: TeacherMapper.java
) else (
    echo 错误: 找不到源文件 TeacherMapper.java
    exit /b 1
)

REM 复制TeacherRoleMapper.java
if exist ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\TeacherRoleMapper.java" (
    copy ".\scms-secondclass\src\main\java\com\scms\secondclass\mapper\TeacherRoleMapper.java" ".\scms-admin\src\main\java\com\scms\secondclass\mapper\TeacherRoleMapper.java" /Y
    echo 复制文件: TeacherRoleMapper.java
) else (
    echo 错误: 找不到源文件 TeacherRoleMapper.java
    exit /b 1
)

REM 复制TeacherMapper.xml
if exist ".\scms-secondclass\src\main\resources\mapper\secondclass\TeacherMapper.xml" (
    copy ".\scms-secondclass\src\main\resources\mapper\secondclass\TeacherMapper.xml" ".\scms-admin\src\main\resources\mapper\secondclass\TeacherMapper.xml" /Y
    echo 复制文件: TeacherMapper.xml
) else (
    echo 错误: 找不到源文件 TeacherMapper.xml
    exit /b 1
)

REM 复制TeacherRoleMapper.xml
if exist ".\scms-secondclass\src\main\resources\mapper\secondclass\TeacherRoleMapper.xml" (
    copy ".\scms-secondclass\src\main\resources\mapper\secondclass\TeacherRoleMapper.xml" ".\scms-admin\src\main\resources\mapper\secondclass\TeacherRoleMapper.xml" /Y
    echo 复制文件: TeacherRoleMapper.xml
) else (
    echo 错误: 找不到源文件 TeacherRoleMapper.xml
    exit /b 1
)

echo 所有文件复制完成，开始清理和编译项目...

REM 清理和编译项目
cd scms-admin
call mvn clean package -DskipTests

if %ERRORLEVEL% NEQ 0 (
    echo 编译失败，请检查错误信息。
    exit /b 1
)

echo 编译成功！

REM 检查端口占用并启动系统
echo 检查端口占用并启动系统...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8089') do (
    echo 发现端口8089被占用，进程ID: %%a
    taskkill /F /PID %%a
    echo 已终止进程 %%a
)

echo 启动系统...
java -jar target\scms-admin.jar

exit /b 0 